/**
 *
 */
package org.suren.littlebird.views;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.suren.littlebird.Activator;
import org.suren.littlebird.preferences.PreferenceConstants;

/**
 * @author suren
 *
 */
public class InstallBundleDialog extends Dialog
{
	private Composite topComp;

	private String bundleFile = "";
	private String bundleDir = "";
	private boolean startAfterInstall = true;

	private Text bundleFileText;
	private Text bundleDirText;
	private Button startCheckBut;

	/**
	 * @param parentShell
	 */
	public InstallBundleDialog(Shell parentShell)
	{
		super(parentShell);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	protected Control createContents(Composite parent)
	{
		return super.createContents(parent);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	protected Control createDialogArea(Composite parent)
	{
		IPreferenceStore store = Activator.getDefault().getPreferenceStore();

		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;

		topComp = new Composite(parent, SWT.None);
		topComp.setLayout(gridLayout);

		new Label(topComp, SWT.None).setText("Bundle File : ");
		bundleFileText = new Text(topComp, SWT.None);

		new Label(topComp, SWT.None).setText("Bundle Dir : ");
		bundleDirText = new Text(topComp, SWT.None);

		new Label(topComp, SWT.None).setText("Start After Install : ");
		startCheckBut = new Button(topComp, SWT.CHECK);
		startCheckBut.setSelection(true);

		bundleFileText.setText(bundleFile);
		bundleDirText.setText(store.getString(PreferenceConstants.P_BUNDLE_DIR));

		return topComp;
	}

	public int open(String absPath)
	{
		this.bundleFile = absPath;

		return open();
	}

	@Override
	protected void buttonPressed(int buttonId)
	{
		if(buttonId == IDialogConstants.OK_ID)
		{
			this.bundleFile = bundleFileText.getText();
			this.bundleDir = bundleDirText.getText();
			this.startAfterInstall = startCheckBut.getSelection();
		}

		super.buttonPressed(buttonId);
	}

	public String getBundleFile()
	{
		return this.bundleFile;
	}

	public String getBundleDir()
	{
		return this.bundleDir;
	}

	public boolean isStartAfterInstall()
	{
		return this.startAfterInstall;
	}
}
